﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using NCT.Framework;
using VISS.API.Commons;

namespace VISS.Web.BackEnd {
    public class SelectCtrlBuilder {
        private const string _template = "<option value=\"{0}\" {1}>{2}</option>";

        public static string ToSlCities(string value) {
            ICity city = StructureMapFactory.GetInstance<ICity>();
            List<CityEnt> listCities = city.GetAll();
            string str = "";
            for (int i = 0; i < listCities.Count(); i++) {
                string selected = "";
                if (listCities[i].ID.ToString() == value) {
                    selected = "selected=\"selected\"";
                }
                str += string.Format(_template, listCities[i].ID, selected, listCities[i].Name);
            }

            return str;
        }

        public static string ToSlJob(string value) {
            IJob job = StructureMapFactory.GetInstance<IJob>();
            List<JobEnt> listjob = job.GetAll();
            string str = "";
            for (int i = 0; i < listjob.Count(); i++) {
                string selected = "";
                if (listjob[i].ID.ToString() == value) {
                    selected = "selected=\"selected\"";
                }
                str += string.Format(_template, listjob[i].ID, selected, listjob[i].Name);
            }

            return str;
        }

        public static string ToSlReligion(string value) {
            IReligion religion = StructureMapFactory.GetInstance<IReligion>();
            List<ReligionEnt> listReligion = religion.GetAll();
            string str = "";
            for (int i = 0; i < listReligion.Count(); i++) {
                string selected = "";
                if (listReligion[i].ID.ToString() == value) {
                    selected = "selected=\"selected\"";
                }
                str += string.Format(_template, listReligion[i].ID, selected, listReligion[i].Name);
            }

            return str;
        }

        public static string ToSlEducation(string value) {
            IEducation education = StructureMapFactory.GetInstance<IEducation>();
            List<EducationEnt> listEducation = education.GetAll();
            string str = "";
            for (int i = 0; i < listEducation.Count(); i++) {
                string selected = "";
                if (listEducation[i].ID.ToString() == value) {
                    selected = "selected=\"selected\"";
                }
                str += string.Format(_template, listEducation[i].ID, selected, listEducation[i].Name);
            }

            return str;
        }

        public static string ToSlMaritalStatus(string value) {
            IMaritalStatus earitalStatus = StructureMapFactory.GetInstance<IMaritalStatus>();
            List<MaritalStatusEnt> listMaritalStatus = earitalStatus.GetAll();
            string str = "";
            for (int i = 0; i < listMaritalStatus.Count(); i++) {
                string selected = "";
                if (listMaritalStatus[i].ID.ToString() == value) {
                    selected = "selected=\"selected\"";
                }
                str += string.Format(_template, listMaritalStatus[i].ID, selected, listMaritalStatus[i].Name);
            }

            return str;
        }

        public static string ToSlSmoking(string value) {
            ISmoking smoking = StructureMapFactory.GetInstance<ISmoking>();
            List<SmokingEnt> listSmoking = smoking.GetAll();
            string str = "";
            for (int i = 0; i < listSmoking.Count(); i++) {
                string selected = "";
                if (listSmoking[i].ID.ToString() == value) {
                    selected = "selected=\"selected\"";
                }
                str += string.Format(_template, listSmoking[i].ID, selected, listSmoking[i].Name);
            }

            return str;
        }
    }
}